package com.cs.framework.domain;

import com.mybatisflex.core.paginate.Page;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *    分页
 * </p>
 * @author wind
 * @date    2024/12/28 17:44
 * @version v1.0
 */
public class PageVO implements Serializable {

    private long pageNum;

    private long pageSize;

    private long total;

    private long page;

    private List<?> records;

    public PageVO(long pageNum, long pageSize, long total, long page, List<?> records) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.page = page;
        this.records = records;
    }

    public static PageVO of(Page<?> page){
        return new PageVO(page.getPageNumber(), page.getPageSize(), page.getTotalRow(), page.getTotalPage(), page.getRecords());
    }

    public long getPageNum() {
        return Math.max(pageNum, 1) - 1;
    }

    public void setPageNum(long pageNum) {
        this.pageNum = pageNum;
    }

    public long getPageSize() {
        return pageSize < 0 ? 10 : pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<?> getRecords() {
        return records;
    }

    public void setRecords(List<?> records) {
        this.records = records;
    }

    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }
}
